const fs = require('fs');
const path = require('path');

// 读取文件
const filePath = path.join(__dirname, 'src/pages/chat/chat.tsx');
let content = fs.readFileSync(filePath, 'utf8');

console.log('🔧 开始完整修复语法错误...');

// 修复第一个useEffect的依赖数组
content = content.replace(
  /}, \[chatId\]\)\n\n  \/\/ 提取Socket连接逻辑到单独函数/,
  '}, [chatId])\n\n  // 提取Socket连接逻辑到单独函数'
);

// 修复第二个useEffect的依赖数组 - 移除重复的变量声明
content = content.replace(
  /}, \[chatId, peerId, pushUniqueMessage, handleVideoOffer, handleVoiceOffer, endVideoCall, endVoiceCall, videoCallId, voiceCallId, refreshMessages\]\)\n\n  \/\/ 页面隐藏时停止自动刷新/,
  '}, [chatId, peerId, pushUniqueMessage, handleVideoOffer, handleVoiceOffer, endVideoCall, endVoiceCall, videoCallId, voiceCallId, refreshMessages])\n\n  // 页面隐藏时停止自动刷新'
);

// 写回文件
fs.writeFileSync(filePath, content, 'utf8');

console.log('✅ 完整语法错误修复完成');
